package mlz.arr;

import java.util.Random;

//数组的应用场景
public class ArrDemo01 {
    public static void main(String[] args) {
        //以前的方式 -> 普通定义变量
        String name1 = "张三1";
        String name2 = "李四1";
        String name3 = "张三2";
        String name4 = "李四2";

        //生成随机数
        Random r = new Random();
        int number = r.nextInt(10) + 1;//1 - 10

        switch (number){
            case 1:
                System.out.println(name1 + "回答问题");
                break;
            case 2:
                System.out.println(name2 + "回答问题");
                break;
            default:
                System.out.println("没有人回答");
        }

        System.out.println("------------------------");

        //数组定义的方式
        String[] names = {"张三1","李四1","张三2","李四2"};
        //生成随机数
        Random r1 = new Random();
        int number1 = r.nextInt(4); // 0-4
        System.out.println(names[number1] + "回答问题");
    }
}
